import { createStore } from 'vuex'
import { getMusicLyric } from '@/request/api/item'
import { getPhoneLogin } from '@/request/api/home'
export default createStore({
  state: {
    playList: [{
      al: {
        id: 139667039,
        name: 'y',
        pic: 109951167203010000,
        picUrl: 'https://p1.music.126.net/ZAOtKCQkxYwvWjk1oTySiA==/109951167203010005.jpg',
        pic_str: '109951167203010005'
      },
      id: 1872132205
    }],
    playListIndex: 0,
    isBtnShow: true,
    detailShow: false,
    lyricList: {},
    currentTime: 0,
    duration: 0, // 歌曲总时长
    isLogin: false,
    isFooterMusic: true,
    token: '',
    userInfo: ''

  },
  mutations: {
    upDateisBtnShow(state, value) {
      state.isBtnShow = value
    },
    upDateplayList(state, value) {
      state.playList = value
    },
    pushplayList(state, value) {
      state.playList.push(value)
    },
    upDateplayListIndex(state, value) {
      state.playListIndex = value
    },
    upDatedetailShow(state) {
      state.detailShow = !state.detailShow
    },
    upDatelyricList(state, value) {
      state.lyricList = value
    },
    upDatecurrentTime(state, value) {
      state.currentTime = value
    },
    upDateduration(state, value) {
      state.duration = value
    },
    upDateisLogin(state, value) {
      state.isLogin = !state.isLogin
    },
    upDateToken(state, value) {
      state.token = value
      localStorage.setItem('token', JSON.stringify(value))
    },
    upDateUser(state, value) {
      state.userInfo = value
      localStorage.setItem('userInfo', JSON.stringify(value))
    }
  },
  actions: {
    async getMusicLyric(context, value) {
      const res = await getMusicLyric(value)
      console.log(res)
      context.commit('upDatelyricList', res.data.lrc)
    },
    async getPhoneLogin(context, value) {
      const res = await getPhoneLogin(value)
      return res
    }
  },
  modules: {
  }
})
